﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using WebSiteAdminTool.UI.Views.SidePanels;
using WebSiteAdminTool.UI.Utils;
using WebSiteAdminTool.UI.ViewModels;
using WebSiteAdminTool.UI.ViewModels.Security.Users;
using WebSiteAdminTool.UI.Views.Base;
using WebSiteAdminTool.UI.Views.Security.Users;

namespace WebSiteAdminTool.UI.Views.Security.Users
{
    public partial class UserManagementPage : BaseNavigationPage
    {
        #region ctors

        public UserManagementPage()
        {
            InitializeComponent();
            
            BuildAlphabetFilterLinks();
        }

        #endregion

        #region overriden base methods
        
        public override BaseUserControl GetActionsPanel()
        {
            var actionPanel = new UserManagementActionsPanel();
            return actionPanel;
        }
        
        #endregion

        #region event handlers

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {

        }
        
        #endregion

        #region helpers

        private void BuildAlphabetFilterLinks()
        {
            // remove all existing items
            pnlAlphabetLinks.Children.Clear();
            // add "All" link
            pnlAlphabetLinks.Children.Add(CreateAlphabetFilterLink("All", null));
            for (int i = (int)'A'; i <= (int)'Z'; i++)
            {
                char c = (char)i;
                pnlAlphabetLinks.Children.Add(CreateAlphabetFilterLink(c.ToString(), c));
            }
        }

        private UIElement CreateAlphabetFilterLink(string linkName, char? filterChar)
        {
            HyperlinkButton link = new HyperlinkButton()
            { 
                Content = linkName,
                TargetName = "_blank",
                Style = StyleHelper.GetApplicationStyle("UserManagementSearchAlphabetLink") as Style,
                Command = (this.DataContext as UserManagementViewModel).AlphaFilterAppliedCommand,
                CommandParameter = filterChar
            };

            return link;
        }

        #endregion
    }
}
